import { useMemo } from 'react';

import type { ThreadContextValue } from '../../threadContext/ThreadContext';
import type { MessageInputContextValue } from '../MessageInputContext';

export const useCreateMessageInputContext = ({
  additionalTextInputProps,
  asyncMessagesLockDistance,
  asyncMessagesMinimumPressDuration,
  asyncMessagesMultiSendEnabled,
  asyncMessagesSlideToCancelDistance,
  AttachButton,
  AttachmentPickerBottomSheetHandle,
  attachmentPickerBottomSheetHandleHeight,
  attachmentPickerBottomSheetHeight,
  AttachmentPickerSelectionBar,
  attachmentSelectionBarHeight,
  AttachmentUploadPreviewList,
  AttachmentUploadProgressIndicator,
  AudioAttachmentUploadPreview,
  AudioRecorder,
  audioRecordingEnabled,
  AudioRecordingInProgress,
  AudioRecordingLockIndicator,
  AudioRecordingPreview,
  AudioRecordingWaveform,
  AutoCompleteSuggestionHeader,
  AutoCompleteSuggestionItem,
  AutoCompleteSuggestionList,
  CameraSelectorIcon,
  closeAttachmentPicker,
  closePollCreationDialog,
  CommandInput,
  CommandsButton,
  compressImageQuality,
  cooldownEndsAt,
  CooldownTimer,
  CreatePollContent,
  CreatePollIcon,
  editMessage,
  FileAttachmentUploadPreview,
  FileSelectorIcon,
  handleAttachButtonPress,
  hasCameraPicker,
  hasCommands,
  hasFilePicker,
  hasImagePicker,
  ImageAttachmentUploadPreview,
  ImageSelectorIcon,
  Input,
  inputBoxRef,
  InputButtons,
  InputEditingStateHeader,
  InputReplyStateHeader,
  MoreOptionsButton,
  openAttachmentPicker,
  openPollCreationDialog,
  pickAndUploadImageFromNativePicker,
  pickFile,
  selectedPicker,
  SendButton,
  sendMessage,
  SendMessageDisallowedIndicator,
  setInputBoxRef,
  setInputRef,
  showPollCreationDialog,
  ShowThreadMessageInChannelButton,
  StartAudioRecordingButton,
  StopMessageStreamingButton,
  takeAndUploadImage,
  thread,
  toggleAttachmentPicker,
  uploadNewFile,
  VideoAttachmentUploadPreview,
  VideoRecorderSelectorIcon,
}: MessageInputContextValue & Pick<ThreadContextValue, 'thread'>) => {
  const threadId = thread?.id;

  const messageInputContext: MessageInputContextValue = useMemo(
    () => ({
      additionalTextInputProps,
      asyncMessagesLockDistance,
      asyncMessagesMinimumPressDuration,
      asyncMessagesMultiSendEnabled,
      asyncMessagesSlideToCancelDistance,
      AttachButton,
      AttachmentPickerBottomSheetHandle,
      attachmentPickerBottomSheetHandleHeight,
      attachmentPickerBottomSheetHeight,
      AttachmentPickerSelectionBar,
      attachmentSelectionBarHeight,
      AttachmentUploadPreviewList,
      AttachmentUploadProgressIndicator,
      AudioAttachmentUploadPreview,
      AudioRecorder,
      audioRecordingEnabled,
      AudioRecordingInProgress,
      AudioRecordingLockIndicator,
      AudioRecordingPreview,
      AudioRecordingWaveform,
      AutoCompleteSuggestionHeader,
      AutoCompleteSuggestionItem,
      AutoCompleteSuggestionList,
      CameraSelectorIcon,
      closeAttachmentPicker,
      closePollCreationDialog,
      CommandInput,
      CommandsButton,
      compressImageQuality,
      cooldownEndsAt,
      CooldownTimer,
      CreatePollContent,
      CreatePollIcon,
      editMessage,
      FileAttachmentUploadPreview,
      FileSelectorIcon,
      handleAttachButtonPress,
      hasCameraPicker,
      hasCommands,
      hasFilePicker,
      hasImagePicker,
      ImageAttachmentUploadPreview,
      ImageSelectorIcon,
      Input,
      inputBoxRef,
      InputButtons,
      InputEditingStateHeader,
      InputReplyStateHeader,
      MoreOptionsButton,
      openAttachmentPicker,
      openPollCreationDialog,
      pickAndUploadImageFromNativePicker,
      pickFile,
      selectedPicker,
      SendButton,
      sendMessage,
      SendMessageDisallowedIndicator,
      setInputBoxRef,
      setInputRef,
      showPollCreationDialog,
      ShowThreadMessageInChannelButton,
      StartAudioRecordingButton,
      StopMessageStreamingButton,
      takeAndUploadImage,
      toggleAttachmentPicker,
      uploadNewFile,
      VideoAttachmentUploadPreview,
      VideoRecorderSelectorIcon,
    }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [cooldownEndsAt, threadId, showPollCreationDialog, selectedPicker],
  );

  return messageInputContext;
};
